home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / OrganicPasswordFieldUI.java < prev    next >
Text File  |  1998-06-30  |  3KB  |  97 lines

  1. /*
  2.  * @(#)OrganicPasswordFieldUI.java    1.4 98/02/02
  3.  * 
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  */
  20.  
  21. package com.sun.java.swing.plaf.organic;
  22.  
  23. import java.awt.*;
  24. import java.awt.event.*;
  25. import com.sun.java.swing.*;
  26. import com.sun.java.swing.border.*;
  27. import com.sun.java.swing.text.*;
  28. import com.sun.java.swing.event.*;
  29. import com.sun.java.swing.plaf.*;
  30. import com.sun.java.swing.plaf.basic.BasicPasswordFieldUI;
  31.  
  32. /**
  33.  * Provides the Windows look and feel for a password field.
  34.  * The only difference from the standard text field is that
  35.  * the view of the text is simply a string of the echo 
  36.  * character as specified in JPasswordField, rather than the 
  37.  * real text contained in the field.
  38.  * <p>
  39.  * Warning: serialized objects of this class will not be compatible with
  40.  * future swing releases.  The current serialization support is appropriate
  41.  * for short term storage or RMI between Swing1.0 applications.  It will
  42.  * not be possible to load serialized Swing1.0 objects with future releases
  43.  * of Swing.  The JDK1.2 release of Swing will be the compatibility
  44.  * baseline for the serialized form of Swing objects.
  45.  *
  46.  * @version 1.4 02/02/98
  47.  * @author  Steve Wilson
  48.  */
  49. public class OrganicPasswordFieldUI extends BasicPasswordFieldUI 
  50.                                 implements FocusListener {
  51.  
  52.     private char cachedEchoChar;
  53.  
  54.     public static ComponentUI createUI(JComponent c) {
  55.         return new OrganicPasswordFieldUI();
  56.     }
  57.  
  58.     public void installUI(JComponent c) {
  59.         super.installUI(c);
  60.     JPasswordField pw = (JPasswordField)c;
  61.     c.addFocusListener(this);
  62.     cachedEchoChar = pw.getEchoChar();
  63.     pw.setEchoChar('-');
  64.     }
  65.  
  66.     public void uninstallUI(JComponent c) {
  67.         super.uninstallUI(c);
  68.     c.removeFocusListener(this);
  69.     JPasswordField pw = (JPasswordField)c;
  70.     pw.setEchoChar(cachedEchoChar);
  71.     }
  72.  
  73.     public void focusGained(FocusEvent e) {
  74.         JTextField f = (JTextField)e.getSource();
  75.     if (f.getBackground() instanceof UIResource)
  76.         f.setBackground(UIManager.getColor("PasswordField.activeBackground"));
  77.     if (f.getBorder() instanceof UIResource)
  78.         f.setBorder(UIManager.getBorder("PasswordField.activeBorder"));
  79.     f.repaint();
  80.     }
  81.  
  82.     public void focusLost(FocusEvent e) {
  83.         JTextField f = (JTextField)e.getSource();
  84.     if (f.getBackground() instanceof UIResource)
  85.         f.setBackground(UIManager.getColor("PasswordField.background"));
  86.     if (f.getBorder() instanceof UIResource)
  87.             f.setBorder(UIManager.getBorder("PasswordField.border"));
  88.     f.repaint();
  89.     }
  90.  
  91. }
  92.  
  93.  
  94.  
  95.  
  96.  
  97.